package com.ruixi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.ruixi.core.AjaxResult;
import com.ruixi.core.BaseController;
import com.ruixi.core.TableDataInfo;
import com.ruixi.domain.User;
import com.ruixi.service.IUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Created by lrzg
 * @Date 2022/8/10 10:59
 * @Description TODO
 */
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private IUserService userService;

    @GetMapping("/test")
    private String test(){
        return "测试";
    }
    @GetMapping("/getAll")
    public AjaxResult getAll(){
        List<User> list = userService.list();
        return AjaxResult.success(list);
    }

    @GetMapping("/list")
    public AjaxResult getAllList(){
        List<User> list = userService.getAllList();
        return AjaxResult.success(list);
    }

    //http://localhost:8888/user/41
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable("id") int id){
        User user = userService.getUserById(id);
        return AjaxResult.success(user);
    }

    @GetMapping("/getPage")
    public TableDataInfo getPage(){
        PageHelper.startPage(1, 3);
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        List<User> list = userService.list();
        return getDataTable(list);
    }

}
